package com.meitianhui.convenitenbuy.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.meitianhui.convenitenbuy.R;

/**
 * Created by Administrator on 2017/11/13.
 */

public class ChooseStoreDialog extends Dialog implements View.OnClickListener {

    private Context context;
    private ChooseStoreDialog dialog = null;
    private DialogClick dialogClick;
    TextView tvCollection;
    TextView tvNear;
    TextView tvOfficial;

    public ChooseStoreDialog(Context context, int theme) {
        super(context, theme);
    }

    public ChooseStoreDialog(Context context, DialogClick dialogClick) {
        super(context);
        this.context = context;
        this.dialogClick = dialogClick;
        dialog = new ChooseStoreDialog(context, R.style.dialog_with_alpha);
        dialog.setContentView(R.layout.dialog_webview_edinburgh);
        dialog.setCanceledOnTouchOutside(true);
        initView(dialog);
        dialog.show();
        //设置dialog的宽度和高度
        try {
            Window win = dialog.getWindow();
            win.getDecorView().setPadding(80, 0, 80, 0);
            WindowManager.LayoutParams lp = win.getAttributes();
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            win.setAttributes(lp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 布局绑定
     */
    private void initView(ChooseStoreDialog dialog) {
        tvCollection = (TextView) dialog.findViewById(R.id.tv_collection);
        tvCollection.setOnClickListener(this);
        tvNear = (TextView) dialog.findViewById(R.id.tv_near);
        tvNear.setOnClickListener(this);
        tvOfficial = (TextView) dialog.findViewById(R.id.tv_official);
        tvOfficial.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_collection:    //收藏
                if (dialogClick != null) {
                    dialogClick.collectionClick();
                }
                break;
            case R.id.tv_near:
                if (dialogClick != null) {
                    dialogClick.nearClick();
                }
                break;
            case R.id.tv_official:
                if (dialogClick != null) {
                    dialogClick.officialClick();
                }
                break;
        }
        stopProgressDialog();
    }

    public void stopProgressDialog() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
            dialog = null;
        }
    }

    public void setOnClickListener(DialogClick l) {
        this.dialogClick = l;
    }

    public interface DialogClick {

        void collectionClick();

        void nearClick();

        void officialClick();
    }

}
